<#include "/java_copyright.include">
<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
package ${basePackage}.service.${module};

import ${basePackage}.common.utils.DateUtil;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ${basePackage}.mapper.${module}.${className}Mapper;
import ${basePackage}.po.${module}.${className}PO;
import ${basePackage}.common.base.R;
import ${basePackage}.service.base.BaseService;
import ${basePackage}.service.${module}.${className}Service;

/**
<#include "/java_description.include">
 */
@Slf4j
@Service
public class ${className}ServiceImpl extends BaseService implements ${className}Service {

    @Autowired
    private ${className}Mapper ${classNameLower}Mapper;

	/**
     * 通过id查询单个对象
     */
    @Override
    public ${className}PO queryById(${className}PO params){
        return ${classNameLower}Mapper.queryById(params);
    }

    /**
     * 通过id查询单个对象
     */
    @Override
    public ${className}PO queryById(Integer id){
        return ${classNameLower}Mapper.queryById(id);
    }

    /**
     * 通过id查询单个对象
     */
    @Override
    public void queryById(${className}PO params, R<${className}PO> r){
        r.setData(queryById(params));
    }

    /**
     * 通过条件查询单个对象
     */
    @Override
    public ${className}PO queryOne(${className}PO params){
        return ${classNameLower}Mapper.queryOne(params);
    }

    /**
     * 通过条件查询单个对象
     */
    @Override
    public void queryOne(${className}PO params, R<${className}PO> r){
        r.setData(queryOne(params));
    }

    /**
     * 查询全部
     */
    @Override
    public List<${className}PO> queryList(${className}PO params){
        return ${classNameLower}Mapper.queryList(params);
    }

    /**
     * 查询全部(分页)
     */
    @Override
    public R<List<?>> queryPageList(${className}PO params){
        R<List<?>> r = new R<List<?>>();
        startPage(params);
        List<${className}PO> list = ${classNameLower}Mapper.queryList(params);
        for (${className}PO cur : list) {
            cur.setEncryptionId(encode(cur.getId()));
        }
        r.setData(list);
        r.setCount(new PageInfo<>(list).getTotal());
        return r;
    }

    /**
     * 查询总数
     */
    @Override
    public int queryCount(${className}PO params){
        return ${classNameLower}Mapper.queryCount(params);
    }

    /**
     * 新增
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R<?> insert(${className}PO params)  {
        params.setCreateTime(DateUtil.getNowDate());
        if (${classNameLower}Mapper.insertSelective(params) == 0) {
            transactionRollBack();
            return R.error("新增失败");
        }
        return R.success();
    }

    /**
     * 批量新增
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R<?> insertBatch(List<${className}PO> list) {
        if (${classNameLower}Mapper.insertBatch(list) == 0) {
            transactionRollBack();
            return R.error("批量新增失败");
        }
        return R.success();
    }

    /**
     * 更新
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R<?> update(${className}PO params)  {
        params.setUpdateTime(DateUtil.getNowDate());
        if (${classNameLower}Mapper.updateById(params) == 0) {
            transactionRollBack();
            return R.error("更新失败");
        }
        return R.success();
    }

    /**
     * 删除
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R<?> updateDel(${className}PO params)  {
        params.setUpdateTime(DateUtil.getNowDate());
        if (${classNameLower}Mapper.updateDel(params) == 0) {
            transactionRollBack();
            return R.error("删除失败");
        }
        return R.success();
    }
}
